package com.zzyl.nursing.controller.member;

import java.time.LocalDateTime;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.common.utils.PageUtils;
import com.zzyl.nursing.vo.AddReservationVo;
import com.zzyl.nursing.vo.CountByTimeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 预约信息Controller
 * 
 * @author alexis
 * @date 2025-06-06
 */
@Api(tags = "预约信息管理")
@RestController
@RequestMapping("/member/reservation")
@Slf4j
public class ReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;


    /**
     * 查询取消预约数量
     * @return
     */
    @GetMapping("/cancelled-cpunt")
    @ApiOperation("查询取消预约数量")
    public AjaxResult cancelledCpunt () {
        reservationService.cancelledCpunt();
        return AjaxResult.success();
    }

    /**
     * 查询时间段内可预约数量
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    public AjaxResult countByTime (@RequestParam Long time) {
        log.info("查询时间段内可预约数量,查询时间：{}",  time);
        List<CountByTimeVo> list = reservationService.countByTime(time);
        return AjaxResult.success(list);
    }

    /**
     * 新增预约信息
     * @param reservationVo
     * @return
     */
    @PostMapping
    public AjaxResult add (@RequestBody AddReservationVo reservationVo) {
        log.info("添加预约信息：{}", reservationVo);
        reservationService.addReservation(reservationVo);
        return AjaxResult.success();
    }

    /**
     * 分页查询预约信息
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/page")
    public TableDataInfo<List<Reservation>> page (@Param("pageNum") Integer pageNum, @Param("pageSize")Integer pageSize , @Param("status") Integer status) {
        log.info("分页查询预约信息,页码：{}，页大小：{}，预约状态：{}", pageNum, pageSize, status);
        // 启动分页
        PageUtils.startPage(pageNum, pageSize);
        List<Reservation> list = reservationService.page(status);
        return getDataTable(list);
    }

    /**
     * 取消预约
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancle")
    @ApiOperation(value = "取消预约")
    public AjaxResult cancle (@PathVariable Long id) {
        log.info("取消预约数据id:{}", id);
        reservationService.cancle(id);
        return AjaxResult.success("操作成功");
    }


}
